package com.whxy02.tolearn.app.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.whxy02.tolearn.app.beans.Comment;
import com.whxy02.tolearn.app.dao.CommentDao;
import com.whxy02.tolearn.app.service.CommentService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class CommentServiceImpl implements CommentService {
    private QueryWrapper<Comment> wrapper=new QueryWrapper<>();
    @Resource
    CommentDao commentDao;

    @Override
    public List<Comment> getAll() throws Exception {
        return commentDao.selectList(null);
    }

    @Override
    public Comment getById(Integer id) throws Exception {
        return commentDao.selectById(id);
    }

    @Override
    public int save(Comment comment) throws Exception {
        return commentDao.insert(comment);
    }

    @Override
    public int removeById(Integer id) throws Exception {
        return commentDao.deleteById(id);
    }

    @Override
    public int change(Comment comment) throws Exception {
        return commentDao.updateById(comment);
    }

    @Override
    public List<Comment> getByIds(List<Integer> ids) throws Exception {
        wrapper.clear();
        wrapper.in("comment_id",ids);
        return commentDao.selectList(wrapper);
    }
}
